local Data= {
    chapter2level={},-- 通过章节ID 寻找 level 数据
    level2chapter={},-- 通过levelId，寻找章节数据，注意:index 表示改levelId,在章节数组中的位置
};

function CloneTable(source,dest)
	assert(source, "param tab is nil");
	assert(typeof(source) == "table", "param tab must be a table");
	local data = dest or {};
	for k, v in pairs(source) do
		if type(v) ~= "table" then
			data[k] = v;
		else
			data[k] = CloneTable(v);
		end;
	end;
	return data;
end;

for _, cfg in ipairs(script:GetChildren()) do
	if cfg.ClassName == "ModuleScript" then
      
		for k, v in pairs((require(cfg))) do

			local newLevels={}
			for i=v.levelRange[1],v.levelRange[2] do
				table.insert(newLevels,i)
			end
			v["levels"]=newLevels
            Data.chapter2level[v.id]=v
            -- table.sort(v.levels,function(a,b)
            --     return a<b
            -- end)
            for j,lv in pairs(v.levels) do
                -- print("关卡Id:",lv,j)
                local d={
                    index=j,
                }
                CloneTable(v,d)
                Data.level2chapter[lv]=d
            end
		end;
	end;
end
-- for k,v in pairs(Data.level2chapter) do
--     for j,p in pairs(v) do
--         print("关卡Id,章节:",k,j,p)
--     end
-- end
return Data
